/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package getrootbahasa;

/**
 *
 * @author WaOnEmperoR
 */
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.CSVLoader;

public class CSVtoArff {

    private String source, dest;

    public CSVtoArff(String a, String b){
        this.source=a;
        this.dest=b;
    }

    public void Convert(){
        try {
            CSVLoader loader = new CSVLoader();
            loader.setSource(new File(this.source));//Path file CSV asal
            Instances data = loader.getDataSet();
            
            // save ARFF
            ArffSaver saver = new ArffSaver();

            saver.setInstances(data);
            saver.setFile(new File(this.dest));//Path file ARFF tujuan
            saver.writeBatch();
        } catch (IOException ex) {
            Logger.getLogger(CSVtoArff.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Object[] getLabel(){
        String hasil ="";
        Object [] isi = null;
        try {
            CSVLoader loader = new CSVLoader();
            loader.setSource(new File(this.source));

            //loader.setNominalAttributes("class_kat");
            isi = loader.getNominalLabelSpecs();
            //hasil = loader.getNominalAttributes();
            
            //loader.setNominalAttributes(source);
        } catch (IOException ex) {
            Logger.getLogger(CSVtoArff.class.getName()).log(Level.SEVERE, null, ex);
        }

        return isi;
    }
}
